//
//  TheRadioGuideListViewController.m
//  TryShopping
//
//  Created by panquanReabam.com on 16/8/26.
//  Copyright © 2016年 RuiBen. All rights reserved.
//

#import "TheRadioGuideListViewController.h"
#import "UIViewExt.h"
#import "HttpRequest.h"
#import "GuideCell.h"
@interface TheRadioGuideListViewController ()<UISearchBarDelegate>

@end
@implementation TheRadioGuideListViewController

{
    
    NSMutableArray*staffIdArray;
    NSMutableArray*staffNameArray;
    UITableView*table;
    UIView*heardView;
    UILabel*how;
    NSString*str;
    
}
@synthesize mDelegate;

-(void)BackAction:(UIButton *)sender{
    
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)viewDidDisappear:(BOOL)animated

{
    
    [super viewDidDisappear:animated];
    self.navigationController.delegate = nil;
    
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    
}

-(void)viewDidLoad{
    
    [super viewDidLoad];


    UIImage* backImage = [UIImage imageNamed:@"fanhui"];
    CGRect backframe = CGRectMake(0,0,30,30);
    UIButton* backButton= [[UIButton alloc] initWithFrame:backframe];
    [backButton setBackgroundImage:backImage forState:UIControlStateNormal];
    backButton.titleLabel.font=[UIFont systemFontOfSize:13];
    [backButton addTarget:self action:@selector(BackAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    self.navigationItem.leftBarButtonItem = leftBarButtonItem;
    self.view.backgroundColor=[UIColor whiteColor];
    self.title=@"选择员工";
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                                     [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:1.0],
                                                                     UITextAttributeTextColor,
                                                                     [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1],
                                                                     UITextAttributeTextShadowColor,
                                                                     [NSValue valueWithUIOffset:UIOffsetMake(0, 0)],
                                                                     UITextAttributeTextShadowOffset,
                                                                     [UIFont fontWithName:@"Helvetica Neue" size:tetlefot],
                                                                     UITextAttributeFont,nil]];
    
    table = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight) style:UITableViewStylePlain];
    table.delegate = self;
    table.dataSource = self;
    table.separatorStyle=UITableViewCellSeparatorStyleNone;
    [self.view addSubview:table];
    
    staffIdArray=[[NSMutableArray alloc]init];
    staffNameArray=[[NSMutableArray alloc]init];


    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString* Token = [user objectForKey:@"tokenId"];
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setValue:Token forKey:@"tokenId"];
     [param setValue:@"2" forKey:@"filterType"];
    [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
    [HttpRequest requestData:@"Business/Guide/List" params:param success:^(BOOL isSuccess, SeverData *severDataDict) {
        if (isSuccess) {
            NSLog(@"====%@",severDataDict.dataDict);
       
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                [Global hideProgressHUDInternal:self.view];
                
                for (NSDictionary* dicc in [severDataDict.dataDict objectForKey:@"DataLine"] )
                {
                   
                        [staffIdArray addObject:[dicc valueForKey:@"staffId"]];
                        [staffNameArray addObject:[dicc valueForKey:@"staffName"]];
                    
                    
                    }
                
                [table reloadData];
            }else{
                [Global hideProgressHUDInternal:self.view];
                
            }
            
        }
        else
        {
           
            [Global hideProgressHUDInternal:self.view];
            [Global showTextHudSub:severDataDict.resultStr view:self.view];
        }
        
    }];


    [table reloadData];
    
    
    
    

    
}
#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [staffNameArray count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    
    GuideCell* cell = (GuideCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        NSArray* nib = [[NSBundle mainBundle] loadNibNamed:@"GuideCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
        UILabel *lineLabel1=[[UILabel alloc] initWithFrame:CGRectMake(10, 55-0.40, ScreenWidth-20, 0.40)];
        lineLabel1.backgroundColor=qianhuiColor;
        [cell.contentView addSubview:lineLabel1];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
   
    if (indexPath.section == 0) {
        cell.staffName.text = [staffNameArray objectAtIndex:indexPath.row] ;
    }
    cell.staffName.font=[UIFont systemFontOfSize:16];
    cell.codeLabel.font=[UIFont systemFontOfSize:14];
    cell.codeLabel.textAlignment=NSTextAlignmentRight;
    cell.codeLabel.textColor=luseColor;
   
    
        if ([[NSString stringWithFormat:@"%@",[staffNameArray objectAtIndex:indexPath.row]]isEqualToString:_staffName]) {
             cell.codeLabel.text=@"选中";
       
        }else{
        
        }
    
        UIButton*jiantou = [[UIButton alloc]init];
        jiantou.frame = CGRectMake(ScreenWidth-40,12, 30, 30);
        jiantou.userInteractionEnabled=NO;
        [jiantou setImage:[UIImage imageNamed:@"shouqi"] forState:UIControlStateNormal];
        [cell.contentView addSubview:jiantou];

    
 
    
    return cell;
}

- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 55;
}


#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    [mDelegate staffId:staffIdArray[indexPath.row] staffName:staffNameArray[indexPath.row]];
    
    [self.navigationController popViewControllerAnimated:YES];

}

@end
